import { _decorator, Component, Node,Label} from 'cc';
const { ccclass, property } = _decorator;

@ccclass('joinRoom')
export class joinRoom extends Component {
    @property(Node) 
    public showLabelList:Node[] = []; 

    public  _inputStr = '';          //保存按键输入字符串
    start() {

    }

    update(deltaTime: number) {
        
    }


    onInputEvent(target,argStr){       
        if(argStr == '删除'){           
            this._inputStr = this._inputStr.slice(0,this._inputStr.length-1);
            this.updateLabelList(this._inputStr)
            return;
        }
        if(argStr == '清空'){
            this._inputStr = '';
            this.updateLabelList(this._inputStr)
            return;
        }

        this._inputStr += argStr;
        this.updateLabelList(this._inputStr);
        
        if(this._inputStr.length === 6){
            globalThis._hallClientMgr._sendMessage('join_room',{roomID:this._inputStr});
            this.node.active = false;
            this._inputStr = '';
            this.updateLabelList(this._inputStr);
        }
    }

    updateLabelList(str){
        for (let i = 0; i < this.showLabelList.length; i++) {
            this.showLabelList[i].getComponent(Label).string = '-';
        }
        for(let i = 0; i < str.length; i++){
            this.showLabelList[i].getComponent(Label).string = this._inputStr[i];
        }

    }
}

